Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network Provider: Cloud subnets refactor #1545

Merged
merged 3 commits into from
Aug 11, 2017
Merged

Network Provider: Cloud subnets refactor #1545

merged 3 commits into from
Aug 11, 2017

Conversation

gildub
Copy link
Contributor

@gildub gildub commented Jun 15, 2017

Networks > Subnets > add/edit one

Replaces $scope with this
Adds ng-cloak and form-change
Removes obsolete miqrequire

Depends upon #1508

https://bugzilla.redhat.com/show_bug.cgi?id=1467725

@gildub gildub changed the title Cloud subnets refactor [WIP]Cloud subnets refactor Jun 15, 2017
@miq-bot miq-bot added the wip label Jun 15, 2017
@gildub gildub changed the title [WIP]Cloud subnets refactor Cloud subnets refactor Jun 16, 2017
@miq-bot miq-bot removed the wip label Jun 16, 2017
@gildub
Copy link
Contributor Author

gildub commented Jun 17, 2017

@dclarizio, would you please assign it, thanks

@gildub gildub changed the title Cloud subnets refactor Network Provider: Cloud subnets refactor Jun 20, 2017
@miq-bot
Copy link
Member

miq-bot commented Jun 20, 2017

@gildub unrecognized command 'label', ignoring...

Accepted commands are: add_label, assign, close_issue, move_issue, remove_label, rm_label, set_milestone

@miq-bot
Copy link
Member

miq-bot commented Jun 20, 2017

@gildub Cannot apply the following label because they are not recognized: networkings

@gildub
Copy link
Contributor Author

gildub commented Jun 20, 2017

@miq-bot add_label networks

@himdel
Copy link
Contributor

himdel commented Jun 23, 2017

Test failure looks valid...

@gildub
Copy link
Contributor Author

gildub commented Jun 28, 2017

@himdel, all green now.

API.get("/api/cloud_subnets/" + cloudSubnetFormId + "?expand=resources&attributes=ext_management_system.name,cloud_tenant.name,cloud_network.name").then(function(data) {
vm.cloudSubnetModel.name = data.name;
vm.cloudSubnetModel.ems_name = data.ext_management_system.name;
vm.cloudSubnetModel.tenant_name = angular.isDefined(data.cloud_tenant) ? data.cloud_tenant.name : undefined;
Copy link
Contributor

@himdel himdel Jun 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI we're trying to remove angular.isDefined, this could be just data.cloud_tenant ? data.cloud_tenant.name : undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that was actually recommended recently, there are cases where the variable ends being undefined and would otherwise breaks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if you need to check for definedness, use data.cloud_tenant !== undefined.

But since you just return undefined when cloud tenant is undefined, you don't need to check that.

This could also be written as data.cloud_tenant && data.cloud_tenant.name.

@himdel
Copy link
Contributor

himdel commented Jun 28, 2017

Not sure the API is quite ready for this...

I have 4 Network managers, choosing 2 of them gives me 0 tentants (that's probably OK), another one is fine, has tenants, and another one gives me...

GET http://localhost:3000/api/providers/10000000000019/cloud_tenants?expand=resources&attributes=id,name

{"error":{"kind":"internal_server_error","message":"undefined method `all' for nil:NilClass","klass":"NoMethodError"}}

After that, chosing the one with tenants and chosing a tenant and filling out a few field by random, I hit Save. .. and all I get is an error screen with Invalid input [cloud_subnet/create]. No further info.

So.. I'm guessing there's some validation missing?

@himdel
Copy link
Contributor

himdel commented Jun 28, 2017

Oh.. saving is not done via the API, it's still using miqAjaxButton..

so .. the Invalid input bit dies with this...

F, [2017-06-28T12:30:08.856331 #16556] FATAL -- : Error caught: [RuntimeError] Invalid input
/home/himdel/manageiq-ui-classic/app/controllers/mixins/checked_id_mixin.rb:72:in `find_record_with_rbac'
/home/himdel/manageiq-ui-classic/app/controllers/cloud_subnet_controller.rb:229:in `new_form_params'
/home/himdel/manageiq-ui-classic/app/controllers/cloud_subnet_controller.rb:65:in `create'

The data that got sent on save was..

name:abc
ems_id:10000000000028
cloud_tenant_id:10r11
network_id:c0f0db9c-846f-4d4e-b058-0db5bfb2cb90
dhcp_enabled:true
network_protocol:ipv4
gateway:127.0.0.4
cidr:32

(I'm not sure these values are valid for those fields, but there's no validation, so I'll assume they are, or the server needs to return a better message :).)

@@ -261,7 +225,7 @@ def new_form_params
if params[:gateway]
options[:gateway] = params[:gateway].blank? ? nil : params[:gateway]
end
options[:ip_version] = params[:network_protocol]
options[:ip_version] = params[:network_protocol] =~ /4/ ? 4 : 6
options[:cloud_tenant] = find_record_with_rbac(CloudTenant, params[:cloud_tenant_id]) if params[:cloud_tenant_id]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. probably caused by missing from_cid here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks.

@gildub
Copy link
Contributor Author

gildub commented Jul 5, 2017

@himdel, this PR depends upon #1508 which is taking care of the API get parts. Saving cannot be done by API because changes of updating model through raw commands calls wrapped in task queues. Let's wait for PR#1508 to be merged.

@miq-bot
Copy link
Member

miq-bot commented Jul 5, 2017

This pull request is not mergeable. Please rebase and repush.

@gildub
Copy link
Contributor Author

gildub commented Jul 6, 2017

@himdel, could you please re-review? Thanks

@himdel
Copy link
Contributor

himdel commented Jul 11, 2017

@gildub Still missing that from_cid.

@gildub
Copy link
Contributor Author

gildub commented Jul 12, 2017

@himdel, I've rebased and re-tested again, the creation works fine, I'm not getting any issues or any missing from_cid. Could you please double check?

@himdel
Copy link
Contributor

himdel commented Jul 12, 2017

@gildub Set your database to REGION other than zero and you will, sorry :).

And yes, you need to use a REGION different than zero, otherwise you'll be missing from_cid from everywhere, since it is not needed for region 0.


Also, none of the other problems I mentioned are fixed, I'm still getting that undefined method 'all' for nil:NilClass when I select a different network manager, and there is no validation on the fields.

And the tests are failing.

Why am I even looking at this?

@gildub
Copy link
Contributor Author

gildub commented Jul 14, 2017

@himdel, the problem(s) your mentioned aren't fixed because I couldn't reproduce it (or them) and because of lack of context/description. Also the tests are failing because an unrelated issue, and this is actually happening way too often maybe because we have cross repos dependencies.

Now that said:

  • I'm going to check the support feature mixin because that's supposed to take care of non supported provider
  • What's the story with the database REGION? I never had to play with this, do you have any reference or documentation link?

Cheers,
Gilles

PS: BTW, this is a re-factor!

@gildub gildub closed this Jul 14, 2017
@himdel
Copy link
Contributor

himdel commented Jul 14, 2017

Also the tests are failing because an unrelated issue, and this is actually happening way too often maybe because we have cross repos dependencies.

Ah, thanks for restarting :). Yes, I feel your pain, it's too often :).

I'm going to check the support feature mixin because that's supposed to take care of non supported provider

Thanks.. if it helps, that problematic provider...

Both providers I can see there are ManageIQ::Providers::Openstack::NetworkManager. The failing one is called "OSP Director Network Manager" the working one "OpenStack Network Manager" but that probably doesn't help.

It looks like the important part is that for the failing one, manager.cloud_tenants is nil, whereas for the other one, it returns a collection of 5 items.

I've created an issue, looks like an API bug.. ManageIQ/manageiq#15569

What's the story with the database REGION? I never had to play with this, do you have any reference or documentation link?

The only documentation I could find is http://manageiq.org/docs/guides/architecture/enterprise#region--enterprise . But a simple explanation is that region is a numerical prefix for all the ID values in the system.

When creating a fresh database instead of importing an existing one, if a REGION file exists in the manageiq/ dir, and contains a number, the database will be created with that region setting, otherwise it will default to 0.

In region 0, from_cid and to_cid do nothing, and all objects will have purely numerical ids (like, 14).

In regions other than 0, any id will be usually shortened in the form of 16r14 for an equivalent id in region 16. (The expanded form being 16000000000014.) And from_cid is needed to convert that 16r14 back to 16000000000014, while to_cid does the opposite transformation.

this is a re-factor!

Understood, but why not make things better than refactoring? :) Or, in this case, at least useable :).

And as long as I can fill out all the fields, sucessfuly click submit, and only then get an error, the form is not quite user friendly. And when that error is a generic exception with Invalid input, not a flash message, and not mentioning a specific field that's wrong.. I think we can both agree that this is something that needs to be fixed, so why not now.

If you want to split this into a purely-controllerAs-refactor PR, and a fix-the-bugs PR, feel free to :).

@gildub
Copy link
Contributor Author

gildub commented Jul 25, 2017

@himdel,

Sorry I missed the support feature which was present for the delete case but for the create/update cases, I just added them.
Thanks for creating ManageIQ/manageiq#15569 .
No worries regarding the REGION, I've added the missing from_cid.

@himdel
Copy link
Contributor

himdel commented Aug 2, 2017

Test failure looks familiar, restarting travis :)

@himdel himdel closed this Aug 2, 2017
@himdel himdel reopened this Aug 2, 2017
vm.cloudSubnetModel.network_protocol = data.network_protocol;
vm.afterGet = true;
vm.modelCopy = angular.copy( vm.cloudSubnetModel );
}).catch(miqService.handleFailure);
miqService.sparkleOff();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not belong here, should be inside that .then function body.. Otherwise, there is no spinner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@himdel
Copy link
Contributor

himdel commented Aug 2, 2017

controllerAs check:

  • uses as vm
  • ManageIQ.angular.scope points to vm
  • does not inject $scope unless needed for a $watch or events, or angularForm
  • using a common button partial
  • uses miq-form
  • uses form-changed, no checkchange
  • no separate edit & new, use the same partial
  • specs
  • no copying values one by one - use Object.assign
  • no miqAjaxButton(url, true) - always submit the actual model, don't rely on magic form serialization
  • no extra $setPristine etc. where it doesn't make sense (form submit, form reset..)
  • no if (condition) return true; else return false;
  • no miqrequired, use required or ng-required

@himdel
Copy link
Contributor

himdel commented Aug 2, 2017

Hey, added the checklist here as well, looks like you just removed the manageiq.angular.scope line, so please return it back, pointing to vm.

As for merging new&edit .. if this doesn't make sense to do in this PR, let me know, I can merge as is (except the scope thing).

The same goes for object.assign - would be nice to solve this here, but if there is a reason not to...

EDIT: but since you're doing changes anyway, I also notice the Placement h3 is off (too much to the left, compared with the others), looks like it should be outside that form-group, not inside.

Replaces $scope with this
Adds ng-cloak and form-change
Removes obsolete miqrequire and so
@gildub
Copy link
Contributor Author

gildub commented Aug 9, 2017

@himdel,

I added back the missing ManageIQ.angular.scope, fix the Spinner.
The H3 alignment is an issue because it needs to appear only after the Network Manager has been selected, in my latest test it looked good, but that's a really annoying one.

Yes I would rather focus on the refactor only part here. Rest assured I'm going to work on merging edit/new and use Object.assign.

Thanks

@miq-bot
Copy link
Member

miq-bot commented Aug 9, 2017

Checked commits https://github.com/gildub/manageiq-ui-classic/compare/51d030caef282c2c49e5717f6474551db7803a62~...cd0b6e6f4ae0bc08dfd563504c5f75434591026d with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 🍰

@himdel himdel merged commit 69bec0a into ManageIQ:master Aug 11, 2017
@himdel himdel added this to the Sprint 67 Ending Aug 21, 2017 milestone Aug 11, 2017
@himdel
Copy link
Contributor

himdel commented Aug 11, 2017

Thanks :) Merged.. but please do look into adding some validations here.

@gildub
Copy link
Contributor Author

gildub commented Aug 14, 2017

@himdel, thanks, will do.

@gildub gildub deleted the Cloud_Subnets-refactor branch August 17, 2017 02:04
@gildub gildub restored the Cloud_Subnets-refactor branch October 6, 2017 02:23
@miq-bot
Copy link
Member

miq-bot commented Oct 6, 2017

@gildub Cannot apply the following label because they are not recognized: fine/yes bug

@gildub gildub deleted the Cloud_Subnets-refactor branch October 6, 2017 02:40
@gildub
Copy link
Contributor Author

gildub commented Oct 8, 2017

The following PRs are taking care of the backport for Fine branch:
ManageIQ/manageiq#16150
#2320

Removing fine/yes and 'bug' labels since the later patches are addressing the issue.

@miq-bot
Copy link
Member

miq-bot commented Oct 8, 2017

@gildub unrecognized command 'remove', ignoring...

Accepted commands are: add_label, assign, close_issue, move_issue, remove_label, rm_label, set_milestone

@simaishi
Copy link
Contributor

Backported to Fine via #2320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants